#include <stdio.h>
#include <stdlib.h>

#define BUF_SIZE 1024

/*
 * A tool to copy file.
 * Compile : gcc my_copy_fgets.c -o my_copy_fgets
 * Usage : ./my_copy_gets file1_path file2_path
 *
 * char *fgets(char *s, int size, FILE *stream);
 * int fputs(const char *s, FILE *stream);
 */
int main(int argc, char *argv[])
{
	if (argc != 3) {
		fprintf(stderr, "Usage : %s file1_path file2_path\n", argv[0]);
		exit(1);
	}

	FILE *fp1 = NULL;
	FILE *fp2 = NULL;

	if ((fp1 = fopen(argv[1], "r")) == NULL) {
		perror("fopen()");
		exit(1);
	}
	if ((fp2 = fopen(argv[2], "w")) == NULL) {
		fclose(fp1);
                perror("fopen()");
		exit(1);
        }

	char buf[BUF_SIZE];
	while (fgets(buf, BUF_SIZE, fp1) != NULL) {
		fputs(buf, fp2);
	}

	fclose(fp2);
	fclose(fp1);

	printf("The num of char in %s is %d\n", argv[1], count);

	exit(0);
}
